#ifndef __WEEDER_KEYFRAME_H
#define __WEEDER_KEYFRAME_H

#include <opencv/cv.h>
#include <vector>
#include <string>
#include <TooN/TooN.h>
#include <TooN/se3.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "Texture.h"
#include "WeederMapPoint.h"

class WeederKeyFrame
{
public:
  WeederKeyFrame(const int nNumberClasses)
  {
    iplOriginal = NULL;
    iplDisplay = NULL;
    gluTextureId = 0;
  }

  ~WeederKeyFrame()
  {
    glDeleteTextures(1, &gluTextureId);
    if(iplOriginal != NULL) 
      cvReleaseImage(&iplOriginal);
    if(iplDisplay != NULL) 
      cvReleaseImage(&iplDisplay);
  }

  void GenerateTexture()
  {
    glDeleteTextures(1, &gluTextureId);
    //Create texture for 3D rendering
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &gluTextureId);
    glBindTexture(GL_TEXTURE_2D, gluTextureId);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, iplDisplay->width, iplDisplay->height, 0, GL_BGR, GL_UNSIGNED_BYTE, iplDisplay->imageData);
    glDisable(GL_TEXTURE_2D);
  }


  std::string sFilename;
  IplImage *iplOriginal;
  IplImage *iplDisplay;
  TooN::SE3<> se3CfromW;    // The coordinate frame of this key-frame as a Camera-From-World transformation
  std::vector<KeyPoint<WeederMapPoint*> > vKeyPoints;
  GLuint gluTextureId;  // Texture for texture mapping from above image

private:
  // Do not allow copy
  WeederKeyFrame(const WeederKeyFrame& k);
  WeederKeyFrame& operator=(const WeederKeyFrame&);
};

#endif

